FROM openeuler-22.03-lts-sp4:latest

ARG VERSION=6.0.2

COPY openGauss-Server-${VERSION}-openEuler22.03-aarch64.tar.bz2 .
COPY gosu-arm64 /usr/local/bin/gosu
COPY openEuler.repo /etc/yum.repos.d/openEuler.repo

ENV GOSU_VERSION 1.17
RUN set -eux; \
    chmod +x /usr/local/bin/gosu

RUN set -eux; \
    dnf install -y bzip2 curl libaio shadow tar findutils util-linux glibc-all-langpacks && \
    groupadd -g 70 omm; \
    useradd -r -u 70 -g omm -m -d /home/omm omm; \
    mkdir -p /var/lib/opengauss && \
    mkdir -p /usr/local/opengauss && \
    mkdir -p /var/run/opengauss  && \
    mkdir /docker-entrypoint-initdb.d && \
    tar -jxf openGauss-Server-${VERSION}-openEuler22.03-aarch64.tar.bz2 -C /usr/local/opengauss && \
    chown -R omm:omm /var/run/opengauss && chown -R omm:omm /usr/local/opengauss && chown -R omm:omm /var/lib/opengauss && chown -R omm:omm /docker-entrypoint-initdb.d && \
    chmod 2777 /var/run/opengauss && \
    rm -rf openGauss-Server-${VERSION}-openEuler22.03-aarch64.tar.bz2 && dnf clean all

ENV LANG en_US.UTF-8
ENV PGDATA /var/lib/opengauss/data

RUN set -eux; \
    echo "export GAUSSHOME=/usr/local/opengauss"  >> /home/omm/.bashrc && \
    echo "export PATH=\$GAUSSHOME/bin:\$PATH " >> /home/omm/.bashrc && \
    echo "export LD_LIBRARY_PATH=\$GAUSSHOME/lib:\$LD_LIBRARY_PATH" >> /home/omm/.bashrc

VOLUME ["/var/lib/opengauss/data"]
EXPOSE 5432

COPY entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/entrypoint.sh; \
    ln -s /usr/local/bin/entrypoint.sh / # backwards compat

ENTRYPOINT ["entrypoint.sh"]
CMD ["gaussdb"]
